#ifndef GAMETD_GAMEMANAGER_H
#define GAMETD_GAMEMANAGER_H

#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include "Manager.h"
#include "../ui/StatusBar.h"
#include "../ui/UpgradePanel.h"
#include "../ui/PlacePanel.h"
#include "../ui/Banner.h"

class GameManager : public Manager<GameManager> {
    friend class Manager<GameManager>;

public:
    int Run(int argc, char **argv);

private:
    GameManager();
    ~GameManager();
    void InitAssert(bool flag, char *errmsg);
    void OnInput();
    void OnUpdate(double delta);
    void OnRender();
    bool GenerateTileMapTexture();
    bool CheckHome(const SDL_Point &idxTileSelected) const;
    bool GetCursorIdxTile(SDL_Point &idxTileSelected, int screenX, int screenY) const;
    bool CanPlaceTower(const SDL_Point &idxTileSelected) const;
    void GetSelectedTileCenterPos(SDL_Point &pos, const SDL_Point &idxTileSelected) const;

private:
    Banner *banner;
    StatusBar statusBar;
    Panel *placePanel = nullptr;
    Panel *upgradePanel = nullptr;
    bool isQuit = false;
    SDL_Event event{};
    SDL_Window *window = nullptr;
    SDL_Renderer *renderer = nullptr;
    SDL_Texture *texTileMap = nullptr;
};

#endif // GAMETD_GAMEMANAGER_H
